package com.turnengine.client.global.user.command.gwt;

import static com.javabi.common.dependency.DependencyFactory.getDependency;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.javabi.codebuilder.generated.gwt.IGeneratedRemoteServiceServlet;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.errorcode.gwt.GwtErrorCodeException;
import com.javabi.command.executor.ICommandExecutorService;
import com.javabi.common.locale.LanguageCountry;
import com.turnengine.client.global.user.command.SetUserLanguage;

/**
 * The Set User Language Servlet.
 */
public class SetUserLanguageServlet extends RemoteServiceServlet implements IGeneratedRemoteServiceServlet, SetUserLanguageService {

	public Boolean setUserLanguage(long loginId, LanguageCountry language) throws GwtErrorCodeException {
		SetUserLanguage command = new SetUserLanguage(loginId, language);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<Boolean> response = service.execute(command);
		if (response.hasErrors()) {
			throw new GwtErrorCodeException(response);
		}
		return response.getReturnValue();
	}
}
